import type {
  KnowledgeParams,
  KnowledgePage,
  PageParams,
  DoctorPage,
  ContentType,
  TopDep,
  Image,
  ConsultOrderPreParams,
  ConsultOrderPreData,
  PartialConsult,
  ConsultOrderItem
} from '@/types/consult'
import { request } from '@/utils/request'

export const getknowledge = (patient: KnowledgeParams) =>
  request<KnowledgePage>('/patient/home/knowledge', 'GET', patient)

export const getdoc = (patient: PageParams) =>
  request<DoctorPage>('/home/page/doc', 'GET', patient)

// 关注
export const followOrUnfollow = (type: ContentType = 'doc', id: string) =>
  request('/like', 'POST', { type, id })

// 请求查询所有科室-层级
export const getAllDep = () => request<TopDep[]>('/dep/all')

// 上传图片
export const uploadImage = (file: File) => {
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('/upload', 'POST', fd)
}

// 拉取预支付订单信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

// 生成订单Id
export const createConsultOrder = (data: PartialConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', data)

// 生成支付地址的 API 函数
// 获取支付地址  0 是微信  1 支付宝
export const getConsultOrderPayUrl = (data: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('/patient/consult/pay', 'POST', data)

// 获取订单详情
export const getConsultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', {
    orderId
  })
